<?php

class MusicHistoryRequest
{
	private $history = array();
	private $category = "";
	private $choir = "all";
	
	public function __construct($choir, $category)
	{
		$this->category=$category;
		$this->choir=$choir;
	}
	
	public function getHistory()
	{
		$choirCondition="";
		if($this->choir=="clerks")$choirCondition="%L%";
		if($this->choir=="boys")$choirCondition="%B%";
		if($this->choir=="girls")$choirCondition="%G%";
		
		
		$database=$GLOBALS['DATABASE']->Recopy();
		$sql = "SELECT ".$this->category.", count(".$this->category.") AS Count FROM MusicAdmin_MusicList WHERE ";
		if($choirCondition!="")
			$sql .= "Choir LIKE '".$choirCondition."' AND ";
		$sql .= $this->category." <> '' ";
		$sql .= "GROUP BY ".$this->category." ORDER BY Count DESC";
		
//		echo $sql;

		$database->executeSQL($sql);
		while($row=$database->getRow())
		{
			$musicResult = array();
			$musicResult['Piece'] = $row[$this->category];
			$musicResult['Count'] = $row['Count'];
			
			array_push($this->history,$musicResult);
		}
		return $this->history;
	}
}
